use indexmap::IndexMap;
use petgraph::algo::{dijkstra, min_spanning_tree};
use petgraph::data::FromElements;
use petgraph::dot::{Config, Dot};
use petgraph::graph::UnGraph;
use petgraph::visit::NodeIndexable;
use std::collections::HashMap;

#[derive(Debug, Clone)]
struct ToolInventory {
    tool_code: String,
    quantity: u32,
}

#[derive(Debug, Clone)]
struct Tool {
    mat_code: String,
    quantity: u32,
}

fn main() {
    let mut graph = UnGraph::<String, ()>::new_undirected();

    let mut inventories = IndexMap::new();
    let mut tools = IndexMap::new();

    let inv1 = ToolInventory {
        tool_code: "GJ001".to_string(),
        quantity: 100,
    };
    let inv2 = ToolInventory {
        tool_code: "92001".to_string(),
        quantity: 200,
    };

    let tool1 = Tool {
        mat_code: "92001".to_string(),
        quantity: 10,
    };
    let tool2 = Tool {
        mat_code: "91001".to_string(),
        quantity: 20,
    };

    inventories.insert(inv1.tool_code.clone(), inv1.clone());
    inventories.insert(inv2.tool_code.clone(), inv2.clone());

    tools.insert(tool1.mat_code.clone(), tool1.clone());
    tools.insert(tool2.mat_code.clone(), tool2.clone());

    let inv1_node = graph.add_node(inv1.tool_code.clone());
    let inv2_node = graph.add_node(inv2.tool_code.clone());
    let tool1_node = graph.add_node(tool1.mat_code.clone());
    let tool2_node = graph.add_node(tool2.mat_code.clone());

    graph.add_edge(inv1_node, tool1_node, ());
    graph.add_edge(inv1_node, tool2_node, ());
    graph.add_edge(inv2_node, tool1_node, ());
    graph.add_edge(inv2_node, tool2_node, ());

    // 现在我们可以进行图操作，例如查找与关联工具
    for neighbor in graph.neighbors(inv1_node) {
        let code = &graph[neighbor];
        if let Some(tool) = tools.get(code) {
            println!(
                "inv1 has tool: {}, quantity: {}",
                tool.mat_code, tool.quantity
            );
        }
    }
}
